<?php
/**
 * 娱乐管理
 * User: admin
 * Date: 2017/12/8
 * Time: 14:07
 */

namespace Admin\Controller;
use Common\Controller\AdminbaseController;


class VideoController  extends AdminbaseController
{

    /**
     * 视频列表
     */
    public function index(){
        $list = M('video')->where('video_type = 1')->order('uptime desc')->select();

        foreach ($list as &$li){
            if($li['type']==1){
                $li['type_txt'] ="平台上传";
            }else if ($li['type'] ==2){
                $li['type_txt'] ="玩家上传";
            }
            if($li['is_charge'] == 1){
                $li['is_charge']="是";
            }else{
                $li['is_charge']="否";
            }

            if($li['is_down'] == 1){
                $li['is_down']="是";
            }else{
                $li['is_down']="否";
            }

            if($li['is_recommend'] == 1){
                $li['is_recommend']="是";
            }else{
                $li['is_recommend']="否";
            }
            if($li['uid'] ==1){
                $li['uid'] = "admin";
            }else{
                if($li['uid']){
                    $user=M('users')->where('id='.$li['uid'])->find();
                    if($user){
                        $li['uid']= $user['user_nicename'];
                    }
                }else{

                }
            }
            //评论数
            $map['video_id'] =$li['id'];
            $li['comment_nums']=M('comment')->where($map)->count();
        }
        $this->assign('lists',$list);
        $this->display();
    }

    /**
     * 添加视频
     */
     public function  add(){
         $data=sp_get_cmf_settings('storage');
         $config1=array(
             'secrectKey' => $data['Qiniu']['secretKey'],
             'accessKey'  => $data['Qiniu']['accessKey'],
             'domain'      => $data['Qiniu']['domain'],
             'bucket'      =>$data['Qiniu']['bucket'],
         );
         $qiniu = new  \Think\QiniuStorage($config1);
         $token = $qiniu->getToken($config1);

         $this->assign('token', $token);
         $this->display();
     }

    /**
     * 添加视频
     */
    public function  add_post(){
        if(IS_POST){

            $video=M("video");
            //  $video->uptime=time();

            $data['type']=1;
            $data['name'] = $_POST['name'];
            $data['video_path'] = $_POST['filekey'];
            $data['thumb2'] = $_POST['thumb2'];
            $data['qiniu_key'] = $_POST['key'];
            $data['is_charge'] =$_POST['is_charge'];
            $data['charge_money'] = $_POST['charge_money'];
            $data['is_down'] = $_POST['is_down'];
            $data['down_money'] = $_POST['down_money'];
            $data['times'] = 0;
            $data['detail'] = $_POST['detail'];
            $data['uptime'] = time();
            $result=$video->add($data);
            if($result){
                $this->success('添加成功',U('index'));
            }else{
                $this->error('添加失败');
            }
        }
    }

    /**
     * 编辑视频
     */
    public  function  edit(){
        $id=I('id');
        $info =M('video')->where('id='.$id)->find();
        $data=sp_get_cmf_settings('storage');
        $config1=array(
            'secrectKey' => $data['Qiniu']['secretKey'],
            'accessKey'  => $data['Qiniu']['accessKey'],
            'domain'      => $data['Qiniu']['domain'],
            'bucket'      =>$data['Qiniu']['bucket'],
        );
        $qiniu = new  \Think\QiniuStorage($config1);
        $token = $qiniu->getToken($config1);

        $this->assign('token', $token);
        $this->assign('info', $info);
        $this->display();
    }

    /**
     * 编辑视频处理
     */
    public function edit_post(){
        if(IS_POST){

            $video=M("video");
            $data['type']=$_POST['type'];
            $data['name'] = $_POST['name'];
            $data['video_path'] = $_POST['filekey'];
            $data['thumb2'] = $_POST['thumb2'];
            $data['qiniu_key'] = $_POST['key'];
            $data['is_charge'] =$_POST['is_charge'];
            $data['charge_money'] = $_POST['charge_money'];
            $data['is_down'] = $_POST['is_down'];
            $data['down_money'] = $_POST['down_money'];
            $data['times'] = $_POST['times'];
            $data['is_recommend'] = $_POST['is_recommend'];
            $data['detail'] = $_POST['detail'];
            $data['uptime'] = time();
            $result=$video->where('id='.$_POST['id'])->save($data);
            if($result){
                $this->success('更新成功',U('index'));
            }else{
                $this->error('更新失败');
            }
        }
    }

    /**
     * 删除视频
     */
    public function del(){
        $id=I('id');
        $qiniu_key=M("video")->where("id=".$id)->getField('qiniu_key');
        $result=M("video")->delete($id);
        $data=sp_get_cmf_settings('storage');
        $config1=array(
            'secrectKey' => $data['Qiniu']['secretKey'],
            'accessKey'  => $data['Qiniu']['accessKey'],
            'domain'      => $data['Qiniu']['domain'],
            'bucket'      =>$data['Qiniu']['bucket'],
        );

        $qiniu = new  \Think\QiniuStorage($config1);
        $qiniu->del($qiniu_key);
        if($result){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 电视剧列表
     */
    public function teleplay(){
        $list = M('video')->where('video_type = 2')->order('uptime desc')->select();
        foreach ($list as &$li){
            if($li['type']==1){
                $li['type_txt'] ="平台上传";
            }else if ($li['type'] ==2){
                $li['type_txt'] ="玩家上传";
            }
            if($li['is_charge'] == 1){
                $li['is_charge']="是";
            }else{
                $li['is_charge']="否";
            }

            if($li['is_down'] == 1){
                $li['is_down']="是";
            }else{
                $li['is_down']="否";
            }

            if($li['is_recommend'] == 1){
                $li['is_recommend']="是";
            }else{
                $li['is_recommend']="否";
            }
            if($li['uid'] ==1){
                $li['uid'] = "admin";
            }else{
                $li['uid'] =M('users')->where('id='.$li['uid'])->getField('user_nicename');
            }
            //评论数
            $map['video_id'] =$li['id'];
            $li['comment_nums']=M('comment')->where($map)->count();
        }

        $this->assign('lists',$list);
        $this->display();
    }

    /**
     *  添加电视剧
     */
    public  function  add_teleplay(){
        $this->display();
    }

    /**
     *  添加电视剧
     */
    public  function  add_teleplay_post(){
        if(IS_POST){
            $video=M("video");
            $data['type']=1;
            $data['name'] = $_POST['name'];
            $data['thumb2'] = $_POST['thumb2'];
            $data['times'] = 0;
            $data['detail'] = $_POST['detail'];
            $data['video_type'] = $_POST['video_type'];
            $data['uptime'] = time();
            $result=$video->add($data);
            if($result){
                $this->success('添加成功',U('teleplay'));
            }else{
                $this->error('添加失败');
            }
        }
    }

    /**
     * 编辑电视剧
     */
    public  function  edit_teleplay(){
        $id=I('id');
        $info =M('video')->where('id='.$id)->find();
        $this->assign('info', $info);
        $this->display();
    }

    /**
     * 编辑电视剧处理
     */
    public function edit_teleplay_post(){
        if(IS_POST){

            $video=M("video");
            $data['type']=$_POST['type'];
            $data['name'] = $_POST['name'];
            $data['thumb2'] = $_POST['thumb2'];
            $data['times'] = $_POST['times'];
            $data['is_recommend'] = $_POST['is_recommend'];
            $data['detail'] = $_POST['detail'];
            $data['uptime'] = time();
            $result=$video->where('id='.$_POST['id'])->save($data);
            if($result){
                $this->success('更新成功',U('teleplay'));
            }else{
                $this->error('更新失败');
            }
        }
    }

    /**
     * 电视剧集数列表
     */
    public  function teleplay_juji(){
         $id= I('id');
         $list = M('teleplay')->where('video_id='.$id)->order('jishu asc')->select();
         foreach ($list as &$li){
             $li['name'] = M('video')->where('id='.$id)->getField('name');
         }
        $this->assign('video_id', $id);
        $this->assign('lists', $list);
        $this->display();
    }

    /**
     * 集数添加
     */
    public function teleplay_juji_add(){
        $id=I('video_id');
        $name = M('Video')->where('id='.$id)->getField('name');
        $data=sp_get_cmf_settings('storage');
        $config1=array(
            'secrectKey' => $data['Qiniu']['secretKey'],
            'accessKey'  => $data['Qiniu']['accessKey'],
            'domain'      => $data['Qiniu']['domain'],
            'bucket'      =>$data['Qiniu']['bucket'],
        );
        $qiniu = new  \Think\QiniuStorage($config1);
        $token = $qiniu->getToken($config1);

        $this->assign('token', $token);
        $this->assign('video_id', $id);
        $this->assign('name', $name);
        $this->display();
    }
    /**
     * 集数添加处理
     */
    public function teleplay_juji_add_post(){
        if(IS_POST){
            $teleplay=M("teleplay");
            $data['video_id'] =$_POST['video_id'];
            $data['jishu'] = $_POST['jishu'];
            $data['is_charge'] = $_POST['is_charge'];
            $data['charge_money'] = $_POST['charge_money'];
            $data['is_down'] = $_POST['is_down'];
            $data['down_money'] = $_POST['down_money'];
            $data['video_path'] = $_POST['filekey'];
            $data['qiniu_key'] = $_POST['key'];
            $data['createtime'] = time();
            $result=$teleplay->add($data);
            if($result){
                $this->success('添加成功',U('teleplay'));
            }else{
                $this->error('添加失败');
            }
        }
    }

    /**
     * 集数编辑
     */
    public function teleplay_juji_edit(){
        $id=I('id');
        $info = M('teleplay')->where('id='.$id)->find();
        $info['name']=M('video')->where('id='.$info['video_id'])->getField('name');
        $data=sp_get_cmf_settings('storage');
        $config1=array(
            'secrectKey' =>  $data['Qiniu']['secretKey'],
            'accessKey'  =>  $data['Qiniu']['accessKey'],
            'domain'      => $data['Qiniu']['domain'],
            'bucket'      => $data['Qiniu']['bucket'],
        );
        $qiniu = new  \Think\QiniuStorage($config1);
        $token = $qiniu->getToken($config1);

        $this->assign('token', $token);
        $this->assign('info', $info);
        $this->display();
    }

    /**
     * 集数编辑处理
     */
    public function teleplay_juji_edit_post(){
        if(IS_POST){
            $teleplay=M("teleplay");
            $data['video_id'] =$_POST['video_id'];
            $data['jishu'] = $_POST['jishu'];
            $data['is_charge'] = $_POST['is_charge'];
            $data['charge_money'] = $_POST['charge_money'];
            $data['is_down'] = $_POST['is_down'];
            $data['down_money'] = $_POST['down_money'];
            $data['video_path'] = $_POST['filekey'];
            $data['qiniu_key'] = $_POST['key'];
            $data['createtime'] = time();
            $result=$teleplay->where('id='.$_POST['id'])->save($data);
            if($result){
                $this->success('添加成功',U('teleplay'));
            }else{
                $this->error('添加失败');
            }
        }
    }

    /**
     * 删除电视剧
     */
    public  function  delteleplay(){
        $id=I('id');
        $flag= M('video')->where('id='.$id)->delete();
        M('teleplay')->where('video_id='.$id)->delete();

        if($flag){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 删除电视剧集数
     */
    public function  deljishu(){
        $id=I('id');
        $qiniu_key=M('teleplay')->where('id='.$id)->getField('qiniu_key');
        $result = M('teleplay')->where('id='.$id)->delete();
        $data=sp_get_cmf_settings('storage');
        $config1=array(
            'secrectKey' => $data['Qiniu']['secretKey'],
            'accessKey'  => $data['Qiniu']['accessKey'],
            'domain'      => $data['Qiniu']['domain'],
            'bucket'      =>$data['Qiniu']['bucket'],
        );

        $qiniu = new  \Think\QiniuStorage($config1);
        $qiniu->del($qiniu_key);
        if($result){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
    /**
     * 免责声明
     */
    public function disclaimer(){
        if(IS_POST) {
            $page=I("post.post");
            $content = htmlspecialchars_decode($page['post_content']);;
            $map['content'] = $content;
            $map['uptime'] = time();
            $result = M('disclaimer')->where('id=1')->save($map);
            if ($result) {
                $this->success('免责声明更新成功');
            } else {
                $this->error('更新失败');
            }
        }
        $result = M('disclaimer')->where('id=1')->find();
        $this->assign('info', $result);
        $this->display();
    }

    /**
     * 评论列表
     */
    public  function commentlist(){
        $key=I('keyword');
        $map='';
        if($key){
            $where['name'] =array('like','%'.$key.'%');
            $video=M('video')->where($where)->find();
            $map['video_id']=$video['id'];
        }

        $list = M('comment')->where($map)->order('uptime desc')->select();
        foreach ($list as &$li){
            $li['uname'] = M('users')->where('id='.$li['uid'])->getField('user_nicename');
            $li['video_name'] = M('video')->where('id='.$li['video_id'])->getField('name');
            $li['content'] = $this->cut_str($li['content'],20);
        }
        $this->assign('lists', $list);
        $this->display();
    }

    /**
     * 查看评论
     */
    public  function  seecomment(){
        $id=I('id');
        $info = M('comment')->where('id='.$id)->find();
        $info['uname'] = M('users')->where('id='.$info['uid'])->getField('user_nicename');
        $info['video_name'] = M('video')->where('id='.$info['video_id'])->getField('name');
        $this->assign('info', $info);
        $this->display();
    }

    /**
     * 删除评论
     */
    public function  delcomment(){
        $id=I('id');
        $flag= M('comment')->where('id='.$id)->delete();
        if($flag){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 娱乐轮播图列表
     */
    public  function carousel(){
        $list = M('carousel')->order('uptime desc')->select();
        foreach ($list as &$li){
            if($li['type'] == 1){
                $li['type_txt'] = "影视轮播";
                $li['video_name'] = M('video')->where('id='.$li['vid'])->getField('name');
            }else if($li['type']==2){
                $li['type_txt'] = "视频轮播";
                $li['video_name'] = M('video')->where('id='.$li['vid'])->getField('name');
            }else if($li['type']==3){
                $li['type_txt'] = "游戏轮播";
                $li['video_name'] = M('game_recommend')->where('id='.$li['vid'])->getField('name');
            }

        }

        $this->assign('lists', $list);
        $this->display();
    }

    /**
     * 添加轮播图
     */
    public function addcarousel(){
        $this->display();
    }

    /**
     * 添加轮播图处理
     */
    public function  addcarousel_post(){
        if(IS_POST){

            $carousel = M("carousel");
            $data['type']=$_POST['type'];
            $data['thumb2'] = $_POST['thumb2'];
            $data['vid'] = $_POST['vid'];
            $data['uptime'] = time();

            $result=$carousel->add($data);
            if($result){
                $this->success('添加成功',U('carousel'));
            }else{
                $this->error('添加失败');
            }
        }
    }

    /**
     * 编辑轮播图
     */
    public function edit_carousel(){
        $id=I('id');
        $info = M('carousel')->where('id='.$id)->find();
        $this->assign('info', $info);
        $this->display();
    }

    /**
     * 编辑轮播图处理
     */
    public function edit_carousel_post(){
         if(IS_POST){

             $id= I('id');
             $carousel = M("carousel");
             $data['type']=$_POST['type'];
             $data['thumb2'] = $_POST['thumb2'];
             $data['vid'] = $_POST['vid'];
             $data['uptime'] = time();

             $result=$carousel->where('id='.$id)->save($data);
             if($result){
                 $this->success('添加成功',U('carousel'));
             }else{
                 $this->error('添加失败');
             }
         }
    }

    /**
     * 删除轮播
     */
    public function  delcarousel(){
        $id=I('id');
        $flag= M('carousel')->where('id='.$id)->delete();
        if($flag){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 游戏推荐
     */
    public function game_recommend(){
        $list = M('game_recommend')->order('uptime desc')->select();
        $this->assign('lists', $list);
        $this->display();
    }

    /**
     * 添加游戏
     */
    public function  add_game(){
        $this->display();
    }

    /**
     * 添加游戏处理
     */
    public function  add_game_post(){
        if(IS_POST){
            $game = M("game_recommend");
            $data['thumb2'] = $_POST['thumb2'];
            $data['name'] = $_POST['name'];
            $data['brief'] = $_POST['brief'];
            $data['url'] = $_POST['url'];
            $data['uptime'] = time();

            $result=$game->add($data);
            if($result){
                $this->success('添加成功',U('game_recommend'));
            }else{
                $this->error('添加失败');
            }
        }
    }

    /***
     * 编辑游戏
     */
    public function edit_game(){
        $id=I('id');
        $info = M('game_recommend')->where('id='.$id)->find();
        $this->assign('info', $info);
        $this->display();
    }

    /**
     * 编辑游戏处理
     */
    public function  edit_game_post(){
        if(IS_POST){
            $game = M("game_recommend");
            $data['thumb2'] = $_POST['thumb2'];
            $data['name'] = $_POST['name'];
            $data['brief'] = $_POST['brief'];
            $data['url'] = $_POST['url'];
            $data['uptime'] = time();

            $result=$game->where('id='.$_POST['id'])->save($data);
            if($result){
                $this->success('编辑成功',U('game_recommend'));
            }else{
                $this->error('编辑失败');
            }
        }
    }

    /**
     * 删除游戏
     */
    public function  delgame(){
        $id=I('id');
        $flag= M('game_recommend')->where('id='.$id)->delete();
        if($flag){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 推荐管理
     */
    public function rec_video(){
      //  $list = M('rec_level')->order('id asc')->select();
        $list=M("experlevel")->order('levelid asc')->select();
        $this->assign('lists', $list);
        $this->display();
    }

    /**
     * 编辑
     */
    public function  rec_video_edit(){
       $id = I('id');
       $info = M('experlevel')->where('levelid='.$id)->find();
       $this->assign('experlevel', $info);
       $this->display();
    }

    /**
     * 编辑处理
     */
    public function   rec_video_edit_post(){
         if(IS_POST){
              $id=I('levelid');
              $data['recommend_ratio']=I('recommend_ratio');
              $data['addtime'] = time();
              $result =M('experlevel')->where('levelid='.$id)->save($data);
             if($result){
                 $this->success('编辑成功',U('rec_video'));
             }else{
                 $this->error('编辑失败');
             }
         }
    }

    /**
     * 推荐的视频列表
     */
    public  function recvideo_list(){
        $id = I('id');
        $lists = M('recommend_video')->order('uptime desc')->select();
        foreach ($lists as &$li){
            $li['name']=M('video')->where('id='.$li['vid'])->getField('name');
            $li['uname']=M('users')->where('id='.$li['uid'])->getField('user_nicename');
            if($li['paytype'] == '1'){
                $li['pay_txt'] = "支付宝";
            }else if ($li['paytype'] == '2'){
                $li['pay_txt'] = "微信";
            }else if ($li['paytype'] == '3'){
                $li['pay_txt'] = "余额";
            }else if ($li['paytype'] == '4'){
                $li['pay_txt'] = "播豆";
            }
        }
        $this->assign('lists', $lists);
        $this->display();
    }

    /**
     * 删除推荐等级
     */
    public function recvideodel(){
        $id = I('id');
        $result = M('recommend_video')->where('id='.$id)->delete();
        if($result){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    /**
     * 推荐用户
     */
    public function recvideo_level(){
        $vid=I('vid');
        $level=I('level');
        $experience=M("experlevel")->where('levelid='.$level)->getField('level_up');


        $where = "user_type = 2";
        if($level==1){
            $where .=" and consumption <= $experience ";
        }else{
            $level2=$level-1;
            $experience2=M("experlevel")->where('levelid='.$level2)->getField('level_up');

            $where .=" and consumption > $experience2";
            $where .=" and consumption <= $experience ";
        }

        $map['vid']   = $vid;
        $map['level'] = $level;
        $push_user = M('push_user')->where($map)->field('uid')->select();
        $ids='';
        foreach ($push_user as $push){
            $ids[] = $push['uid'];
        }
        $maps['id'] = array('not in',$ids);

        $lists=M('users')->where($where)->where($maps)->select();
        //echo M('users')->where($where)->where($maps)->getLastSql();

        $this->assign('lists', $lists);
        $this->assign('video_id',$vid);
        $this->assign('level',$level);
        $this->display();
    }

    /**
     *推荐推送
     */
    public function push(){
        $ids=I('ids');
        $video_id=I('video_id');
        $level= I('level');
        $title = M('video')->where('id='.$video_id)->getField('name');
        //极光推送消息
        $res=  R('Push/sendToPser',array($title,$ids,$video_id));

        if($res) {
            for($i=0;$i<count($ids);$i++){
                $data='';
                $data['uid'] =$ids[$i];
                $data['vid'] = $video_id;
                $data['level'] = $level;
                $data['uptime'] = time();
              //  M('push_user')->add($data);
            }

            $this->success('推送成功',U('recvideo_list'));
        }else{
            $this->success('推送失败',U('recvideo_list'));
        }

    }
    /**
     * 添加推荐视频处理
     */
    public function recvideo_add_post(){
        $id=I('id');
        $level=I('levelid');
        $result = M('video')->where('id='.$id)->setField('rec_level',$level);
        if($result){
            $this->success('添加成功',U('rec_video'));
        }else{
            $this->error('添加失败');
        }
    }

    /**
     * 首页推荐
     */
    public function top_rec(){
        $list = M('top_rec')->order('uptime desc,type asc')->select();
        foreach ($list as &$li){
            if($li['type'] ==1){
                $li['type_txt'] = "电影推荐";
            }else if($li['type'] == 2){
                $li['type_txt'] = "电视剧推荐";
            }else if ($li['type'] == 3){
                $li['type_txt'] = "视频推荐";
            }
            $li['name'] = M('video')->where('id='.$li['vid'])->getField('name');
        }
        $this->assign('lists', $list);
        $this->display();
    }

    /**
     * 首页推荐视频
     */
    public function  top_rec_add(){
        $this->display();
    }

    /**
     * 首页推荐视频处理
     */
    public function top_rec_add_post(){
        if(IS_POST){
            $data['vid']=I('vid');
            $data['thumb2']=I('thumb2');
            $data['type']=I('type');
            $data['uptime'] = time();
            $result =M('top_rec')->add($data);
            if($result){
                $this->success('保存成功',U('top_rec'));
            }else{
                $this->error('保存失败');
            }
        }
    }

    /**
     * 首页推荐视频编辑
     */
    public function top_rec_edit(){
        $id= I('id');
        $top_rec= M('top_rec')->where('id='.$id)->find();
        $this->assign('info', $top_rec);
        $this->display();
    }


    /**
     * 首页推荐视频编辑处理
     */
    public function top_rec_edit_post()
    {
        if (IS_POST) {
            $id = I('id');
            $data['vid'] = I('vid');
            $data['thumb2'] = I('thumb2');
            $data['type'] = I('type');
            $data['uptime'] = time();
            $result = M('top_rec')->where('id=' . $id)->save($data);
            if ($result) {
                $this->success('保存成功', U('top_rec'));
            } else {
                $this->error('保存失败');
            }
        }

    }

    /**
     * 删除首页推荐
     */
    public function top_rec_del(){
         $id=I('id');
         $result = M('top_rec')->where('id='.$id)->delete();
         if($result){
             $this->success('保存成功');
         }else{
             $this->error('保存失败');
         }
    }
        //字符串截取
    function cut_str($sourcestr,$cutlength)
    {
        $returnstr='';
        $i=0;
        $n=0;
        $str_length=strlen($sourcestr);//字符串的字节数
        while (($n<$cutlength) and ($i<=$str_length))
        {
            $temp_str=substr($sourcestr,$i,1);
            $ascnum=Ord($temp_str);//得到字符串中第$i位字符的ascii码
            if ($ascnum>=224)    //如果ASCII位高与224，
            {
                $returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范，将3个连续的字符计为单个字符
                $i=$i+3;            //实际Byte计为3
                $n++;            //字串长度计1
            }
            elseif ($ascnum>=192) //如果ASCII位高与192，
            {
                $returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范，将2个连续的字符计为单个字符
                $i=$i+2;            //实际Byte计为2
                $n++;            //字串长度计1
            }
            elseif ($ascnum>=65 && $ascnum<=90) //如果是大写字母，
            {
                $returnstr=$returnstr.substr($sourcestr,$i,1);
                $i=$i+1;            //实际的Byte数仍计1个
                $n++;            //但考虑整体美观，大写字母计成一个高位字符
            }
            else                //其他情况下，包括小写字母和半角标点符号，
            {
                $returnstr=$returnstr.substr($sourcestr,$i,1);
                $i=$i+1;            //实际的Byte数计1个
                $n=$n+0.5;        //小写字母和半角标点等与半个高位字符宽...
            }
        }
        if ($str_length>$i){
            $returnstr = $returnstr . "...";//超过长度时在尾处加上省略号
        }
        return $returnstr;
    }

}